# import time
#
# from selenium import webdriver
# from selenium.webdriver.chrome.service import Service
# from selenium.webdriver.common.by import By
# from selenium.common.exceptions import NoSuchElementException
#
# # 指明服务驱动路径
# seriver = Service(executable_path="D:\chromedriver.exe")
#
# # 打开浏览器
# driver = webdriver.Chrome(service=seriver)
# # 最大化
# driver.maximize_window()
#
# # 打开页面
# driver.get("https://www.360kan.com/short/index.html")
#
#
# while True:
#   执行JS代码
# 	driver.execute_script('window.scroll(0, document.body.scrollHeight)')
# 	time.sleep(3)
#
# 	try:
# 		retry = driver.find_element(By.CLASS_NAME, "retry")
# 		break
# 	except NoSuchElementException as e:
# 		pass
#
# items = driver.find_elements(By.CLASS_NAME, "video-item")
# print(len(items))
#
#
# # # 退出浏览器
# driver.quit()
#
#


# import time
#
# from selenium import webdriver
# from selenium.webdriver.chrome.service import Service
# from selenium.webdriver.common.by import By
#
# # 指明服务驱动路径
# seriver = Service(executable_path="D:\chromedriver.exe")
#
# # 打开浏览器
# driver = webdriver.Chrome(service=seriver)
# # 最大化
# driver.maximize_window()
#
#
# driver.get("https://quotes.toscrape.com")
#
# # 添加cookie
# driver.add_cookie({'name' : 'session', 'value' : 'eyJjc3JmX3Rva2VuIjoiSmNNTllkWExLbk9makNpdHhydlBUekZSbUlaRW9HU0hlYndXcWthUWxoQXNndVVCVkR5cCIsInVzZXJuYW1lIjoiYWRtaW4ifQ.aAChrA.TUbXqiqvUVhwC4s8Ph3zZJC3tVQ'})
# driver.get("https://quotes.toscrape.com/page/1/")
#
#
#
# user_state = driver.find_element(By.XPATH, '//div[@class="col-md-4"]/p/a')
# print(user_state.text)
#
# driver.quit()


from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

# 指明服务驱动路径
seriver = Service(executable_path="D:\chromedriver.exe")

# 打开浏览器
driver = webdriver.Chrome(service=seriver)
# 最大化
driver.maximize_window()

driver.get("https://www.celma.org.cn/zqxx/index.jhtml")

# time.sleep(3)
# 隐式等待
# driver.implicitly_wait(10)
# 显式等待

count = 0
while count < 1647:
    print(f"正在爬取第{count + 1} 页")
    WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//table//tr[@data-index]")))

    trs = driver.find_elements(By.XPATH, "//table//tr[@data-index]")
    print(trs)

    page_next = driver.find_element(By.XPATH, "//li[contains(@class, 'page-next')]/a")
    page_next.click()
    count += 1

driver.quit()
